﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using TDM.WebBase;

namespace TDM.WebSvr
{
    public class AppHostStartup : NXDO.WebAPI.ApiStartup
    {
        public AppHostStartup(IConfiguration configuration) : base(configuration)
        {
        }

        protected override void LoadConfigure()
        {
            base.LoadConfigure();
        }

        public override void ConfigureServices(IServiceCollection services)
        {
            base.ConfigureServices(services);
        }

        public override void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
        {
            base.Configure(app, env, hostApplicationLifetime);
            //初始化系统基础地址
            InitSystemBathPath();

        }

        private void InitSystemBathPath()
        {
            //// 构建配置对象
            //IConfiguration config = new ConfigurationBuilder()
            //    .SetBasePath(Directory.GetCurrentDirectory())  // 设置配置文件所在目录
            //    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)  // 加载JSON文件
            //    .Build();
            //TDM.WebBase.BasePathHelper.BasePath = config["BathPath"];
            var baseUrl = Configuration.GetValue<string>("vueSetting:baseUrl");
            //var virPath = Configuration.GetValue<string>("vueSetting:virPath");
            BasePathHelper.BasePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Configuration.GetValue<string>("vueSetting:folder"), "tdmfile");
            WebConfigHelper.SetBaseFileUrl(baseUrl + "/tdmfile");
        }
    }
}
